<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>机构管理</title>
    <script type="text/javascript">
        $(document).ready(function () {
            var url = "[[@{/sys/office/checkName}]]";
            $("#name").focus();
            var validateMessageBox = $('#validateMessageBox');
            var officeEditForm = $('#officeEditForm');
            officeEditForm.validate({
                errorElement: 'label',
                errorClass: 'help-block',
                focusInvalid: true,
                ignore: "",
                
                rules: { 
                },
                messages: {
                },
                errorContainer: validateMessageBox,
                errorPlacement: function (error, element) {

                    this.errorContainer.addClass('note-danger').html("<p>输入有误，请先更正。</p>").show();
                    var formGroup = $(element).closest('.form-group');
                    var errorElement = formGroup.children('span.' + this.errorClass);
                    if (!errorElement || errorElement.length == 0) {
                        errorElement = $('<span/>').addClass(this.errorClass);
                        errorElement.appendTo(formGroup);
                    }
                    error.appendTo(errorElement);

                },
                highlight: function (element) {
                    $(element).closest('.form-group').removeClass('has-success').addClass('has-error');
                },

                unhighlight: function (element) {
                    $(element).closest('.form-group').removeClass('has-error').addClass('has-success');
                },

                success: function (label, element) {
                    label.closest('.form-group').removeClass('has-error');
                },

                submitHandler: function (form) {
                    App.blockUI(window, true);
                    var $officeDetail = $("#officeDetail");
                    $("#officeEditForm")[0].submit();
                }
            });
        });

        function goBack() {
            location.href = "[[@{/sys/office}]]";
        }
    </script>
</head>
<body shiro:has-permission="sys:office:view">
<div th:replace="fragments/tool :: tipMessage (type='',content=${message})" th:remove="tag"></div>
<!-- BEGIN FORM-->
<form id="officeEditForm" class="form-horizontal" th:object="${office}" th:action="@{/sys/office/save}" method="post">
    <input type="hidden" th:field="*{id}"/>

    <div class="form-body" style="background-color: #fff;">
        <div class="form-group">
            <label class="col-md-3 control-label">上级机构<span class="required">*</span></label>

            <div class="col-md-6">
                <input id="parent_id" name="parent.id" th:value="${office.parent.id}" type="hidden" class="office-id"/>
                <input id="parent_name" name="parent.name" th:value="${office.parent.name}" readonly="readonly"
                       type="text"
                       class="form-control required"/>
                       <p></p>
            </div>
        </div>
        <div class="form-group">
            <label class="col-md-3 control-label">机构名称<span class="required">*</span></label>

            <div class="col-md-6">
                <input type="text" th:field="*{name}" maxlength="40" class="form-control required orgName" title="请输入有效机构名称                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          " th:readonly="${not #strings.isEmpty(office.id)}"/>
            </div>
        </div>
        <th:block th:if="${not #strings.isEmpty(office.id) and not #strings.equals(office.type,'2')}">
	        <div class="form-group">
	            <label class="col-md-3 control-label">机构编码</label>
	            <div class="col-md-6">
	                <input type="text" class="form-control" th:field="*{code}"  th:readonly="true"/>
	            </div>
	        </div>
        </th:block>
        <div class="form-group">
            <label class="col-md-3 control-label">机构类型</label>

            <div class="col-md-6">
            	<th:block th:if="${not #strings.isEmpty(office.id)}">
            		<input th:field="*{type}" type="hidden"/>
              		<input class="form-control"  th:readonly="true" type="text" th:value="${@userMenus.getDictLabel(office.type, 'sys_office_type', '无')}"/>
              	</th:block>
              	<th:block th:if="${#strings.isEmpty(office.id)}">
                    <select th:field="*{type}" class="form-control" >
	                    <option th:each="item,stat : ${@userMenus.getDictList('sys_office_type')}" th:value="${item.value}"
	                            th:text="${item.label}">label
	                    </option>
                	</select>
				</th:block>
               
            </div>
        </div>
        <div class="form-group">
            <label class="col-md-3 control-label">联系地址</label>

            <div class="col-md-6">
                <input type="text" class="form-control" th:field="*{address}" maxlength="50" />
            </div>
        </div>
        <div class="form-group">
            <label class="col-md-3 control-label">邮政编码</label>

            <div class="col-md-6">
                <input type="text" class="form-control" th:field="*{zipCode}" maxlength="10" />
            </div>
        </div>
        <div class="form-group">
            <label class="col-md-3 control-label">负责人</label>

            <div class="col-md-6">
                <input type="text" class="form-control" th:field="*{master}" maxlength="10" />
            </div>
        </div>
        <div class="form-group">
            <label class="col-md-3 control-label">电话</label>

            <div class="col-md-6">
                <input type="text" class="form-control" th:field="*{phone}" maxlength="15" />
            </div>
        </div>
        <div class="form-group">
            <label class="col-md-3 control-label">传真</label>

            <div class="col-md-6">
                <input type="text" class="form-control" th:field="*{fax}" maxlength="15" />
            </div>
        </div>
        <div class="form-group">
            <label class="col-md-3 control-label">邮箱</label>

            <div class="col-md-6">
                <input type="text" class="form-control" th:field="*{email}" maxlength="50" />
            </div>
        </div>
        <div class="form-group last">
            <label class="col-md-3 control-label">描述</label>

            <div class="col-md-6">
                <textarea class="form-control" th:field="*{remarks}" rows="3" maxlength="100"
                          ></textarea>
            </div>
        </div>

    </div>
    <div class="form-actions fluid" style="background-color: #ffffff;border: none;">
        <div class="col-md-offset-3 col-md-6" style="text-align: right;">
            <button type="submit" class="btn blue" shiro:has-any-permissions="sys:office:add,sys:office:edit">保 存</button>
            <th:block th:if="${office.id} != null">
                <a th:href="@{/sys/office/delete(id=${office.id})}" shiro:has-permission="sys:office:delete"
                   onclick="return App.confirm('要删除该机构吗？', this.href)"
                   class="btn red">删除</a>
            </th:block>
        </div>
    </div>
</form>
<!-- END FORM-->

</body>
</html>
